www.gusucode.com > windows ce的界面编程源码程序 > windows ce的界面编程源码程序/demo/demo/UiButtonX.cpp

    #include "UiButtonX.h"

UiButtonX::UiButtonX()
{
	iAlpha = 255;
	UiButtonEx::UiButtonEx();
}

void UiButtonX::SetAlpha( UINT Alpha )
{
	iAlpha = Alpha;
	if ( iAlpha > 255 ) iAlpha = 255;
	if ( iAlpha < 0 ) iAlpha = 0;
}

void UiButtonX::OnPaint( HDC hdcDst , RECT * prcWin , RECT * prcUpdate )
{
	if ( iAlpha == 255 )
	{
		UiButtonEx::OnPaint( hdcDst , prcWin , prcUpdate );
	}
	else
	{
		HDC hBuffer = CreateCompatibleDC( hdcDst );
		HBITMAP hbmpBuffer = CreateCompatibleBitmap( hdcDst , prcWin->right - prcWin->left , prcWin->bottom - prcWin->top );
		HBITMAP hbmpOldBitmap = (HBITMAP)SelectObject( hBuffer , hbmpBuffer );

		BitBlt( hBuffer , 0 , 0 , prcWin->right - prcWin->left , prcWin->bottom - prcWin->top , hdcDst , prcWin->left , prcWin->top , SRCCOPY );

		RECT prcNew;
		SetRect( &prcNew , 0 , 0 , prcWin->right - prcWin->left , prcWin->bottom - prcWin->top );

		UiButtonEx::OnPaint( hBuffer , &prcNew , prcUpdate );

		//Do AlphaBlend
		BLENDFUNCTION bf;
		bf.AlphaFormat = 0;
		bf.BlendFlags = 0;
		bf.BlendOp = 0;
		bf.SourceConstantAlpha = iAlpha;

		AlphaBlend( hdcDst ,
					prcWin->left ,
					prcWin->top ,
					prcWin->right - prcWin->left ,
					prcWin->bottom - prcWin->top ,
					hBuffer ,
					0 ,
					0 ,
					prcWin->right - prcWin->left ,
					prcWin->bottom - prcWin->top ,
					bf );
		//

		SelectObject( hBuffer , hbmpOldBitmap );
		DeleteObject( hbmpBuffer );
		DeleteDC( hBuffer );
	}
}